<%-- Created by IntelliJ IDEA. User: Administrator Date: 2023/1/27 Time: 13:11
To change this template use File | Settings | File Templates. --%> <%@ page
contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>订单详情</title>
    <!-- 引入 js 和 样式 -->
    <jsp:include page="../common/css_js.jsp" />
    <jsp:include page="../common/table.jsp"/>
    <style>
      #tab {
        font-size: 18px;
        margin: 0 auto;
        width: 1100px;
        height: 110px;
      }

      #tab tr td:first-child {
        width: 150px;
        text-align: right;
        font-weight: bolder;
      }

      #tab tr td:nth-child(3) {
        text-align: right;
        font-weight: bolder;
      }

      #tab input {
        width: 280px;
        background-color: white;
      }
    </style>
  </head>
  <body>
    <div class="container col-lg-12">
      <div class="card">
        <header class="card-header">
          <div class="card-title">
            <h4><b>订单信息</b></h4>
          </div>
        </header>
        <div class="card-body">
          <div class="row">
            <div class="col-md-4 column">
              <!-- 客户信息 -->
                <table id="tab">
                  <tr>
                    <td>订单编号：</td>
                    <td>
                      <label
                        ><input
                          class="form-control"
                          name="order_no"
                          value="${order.orderNo}"
                          readonly="readonly"
                      /></label>
                    </td>
                    <td>下单时间：</td>
                    <td>
                      <label
                        ><input
                          class="form-control"
                          name="order_date"
                          value="${order.orderDate}"
                          readonly="readonly"
                      /></label>
                    </td>
                  </tr>
                  <tr>
                    <td>订单地址：</td>
                    <td>
                      <label
                        ><input
                          class="form-control"
                          name="order_address"
                          value="${order.orderAddress}"
                          readonly="readonly"
                      /></label>
                    </td>
                    <td>订单状态：</td>
                    <td>
                      <label
                        ><input class='form-control' name='order_state'
                        value="${order.orderState eq 1?"已支付":"未支付"}"
                        readonly='readonly'></label
                      >
                    </td>
                  </tr>
                </table>
            </div>
          </div>
        </div>
      </div>
      <div class="card">
        <header class="card-header">
          <div class="card-title">
            <h4><b>订单详情</b></h4>
          </div>
        </header>
        <div class="card-body">
          <!-- 条件查询表单 -->
          <form
            class="form-inline"
            name="form1"
            action="#"
            method="post"
            id="toolbar"
          >
            <!-- 操作 -->
            <a class="btn btn-primary" onclick="toAdd()"
              ><span class="mdi mdi-plus"></span>新增</a
            >
            &nbsp;
            <a class="btn btn-danger" onclick="batchDelete('order-detail')"
              ><span class="mdi mdi-delete"></span>批量删除</a
            >
            &nbsp;
            <a class="btn btn-primary" onclick="query()"
              ><span class="mdi mdi-table-large"></span>显示所有</a
            >
            &nbsp;&nbsp;
            <b>商品名称：</b>
            <label
              ><input
                style="width: 150px"
                name="goodsName"
                class="form-control"
                placeholder="请输入商品名称"
            /></label>
            &nbsp;
            <b>商品价格：</b>
            <label
              ><input
                name="goodsPriceMin"
                style="width: 80px"
                value="0"
                class="form-control"
                placeholder="请输入最低价格"
            /></label>
            &nbsp;—&nbsp;
            <label
              ><input
                style="width: 80px"
                name="goodsPrice"
                value="0"
                class="form-control"
                placeholder="请输入最高价格"
            /></label>
            &nbsp;&nbsp;
            <button type="button" class="btn btn-primary" onclick="like()">
              <span class="mdi mdi-table-search"></span>搜索
            </button>
          </form>
          <!-- 数据显示 -->
          <div class="table-responsive">
            <table id="table"></table>
          </div>
          <div class="container row">
            <a
              class="btn btn-primary"
              href="${ctx}/page/order/${order.customerId}"
              ><span class="mdi mdi-keyboard-backspace"></span>返回</a
            >
          </div>
        </div>
      </div>
    </div>

    <!-- Modal -->
    <div
      class="modal fade bd-example-modal-lg"
      id="myModal"
      tabindex="-1"
      role="dialog"
      aria-labelledby="myModalLabel"
    >
      <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h4 class="modal-title" id="myModalLabel">新增订单详情</h4>
            <div class="col-md-2 column"></div>
            <div class="col-md-4 column" id="close"></div>
            <button
              type="button"
              class="close"
              data-dismiss="modal"
              aria-label="Close"
            >
              <a aria-hidden="true">&times;</a>
            </button>
          </div>
          <div class="modal-body" style="background-color: #f8faf7">
            <!-- 增加修改表单 -->
            <div class="table-responsive">
              <form>
                <table class="table table-bordered table-hover" id="tab333">
                  <input type="hidden" name="id" />
                  <input type="hidden" name="orderId" value="${order.id}" />
                  <tr>
                    <td>商品名称：</td>
                    <td>
                      <label
                        ><input
                          name="goodsName"
                          class="form-control"
                          placeholder="请输入商品名称"
                      /></label>
                    </td>
                  </tr>
                  <tr>
                    <td>商品数量：</td>
                    <td>
                      <label
                        ><input
                          name="goodsNum"
                          class="form-control"
                          placeholder="请输入商品数量"
                      /></label>
                    </td>
                  </tr>
                  <tr>
                    <td>商品单位：</td>
                    <td>
                      <label
                        ><input
                          name="goodsUnit"
                          class="form-control"
                          placeholder="请输入商品单位"
                      /></label>
                    </td>
                  </tr>
                  <tr>
                    <td>商品价格：</td>
                    <td>
                      <label
                        ><input
                          name="goodsPrice"
                          class="form-control"
                          placeholder="请输入商品价格"
                      /></label>
                    </td>
                  </tr>
                </table>
              </form>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">
              关闭
            </button>
            <button
              type="button"
              id="btn111"
              class="btn btn-primary"
              onclick="insert_update()"
            >
              保存
            </button>
          </div>
        </div>
      </div>
    </div>
    <script type="text/javascript">
      // 加载事件
      $(function () {
        // 初始化表格
        $("#table").bootstrapTable({
          classes: "table table-bordered table-hover table-striped text-nowrap", // 表格样式
          url: "${ctx}/order-detail/list?orderId=${order.id}", // 请求后台的URL
          method: "GET", // 请求方式
          toolbar: "#toolbar",
          pagination: true, //是否显示分页条
          pageNumber: 1, // 首页页码，默认为1
          pageSize: 5, //一页显示的行数
          paginationLoop: false, //是否开启分页条无限循环，最后一页时点击下一页是否转到第一页
          pageList: [5, 10, 20], //选择每页显示多少行，数据过少时可能会没有效果
          clickToSelect: true, // 是否启用点击选中行
          undefinedText: "-", // 当字段为 undefined 显示
          sortOrder: "asc", // 排序方式
          showColumns: true, // 是否显示所有的列
          showRefresh: true, // 是否显示刷新按钮
          showToggle: true, // 是否显示详细视图和列表视图的切换按钮(clickToSelect同时设置为true时点击会报错)
          showExport: true, // 是否显示导出按钮, 导出功能需要导出插件支持(tableexport.min.js)
          exportDataType: "all", // 导出数据类型, 'basic':当前页, 'all':所有数据, 'selected':选中的数据
          // 响应处理
          responseHandler: function (res) {
            if (res.code !== 200) {
              notify("mdi mdi-close", res.message, "danger");
              return [];
            }

            return res.data;
          },
          // 查询参数
          queryParams: function () {
            // 查询条件
            return $("[name='form1']").serializeArray(); // 得到条件查询表单中所有的值
          },
          columns: [
            {
              // 列
              field: "example",
              checkbox: true, // 是否显示复选框
            },
            {
              field: "no",
              align: "center",
              title: "序号",
              formatter: function (value, row, index) {
                return index + 1;
              },
            },
            {
              field: "id",
              title: "编号",
              visible: false,
            },
            {
              field: "goodsName",
              align: "center",
              title: "商品名称",
            },
            {
              field: "goodsNum",
              align: "center",
              title: "商品数量",
            },
            {
              field: "goodsUnit",
              align: "center",
              title: "商品单位",
            },
            {
              field: "goodsPrice",
              align: "center",
              title: "商品价格(元)",
            },
            {
              field: "sum",
              align: "center",
              title: "小计(元)",
              formatter: function (value, row, index) {
                return (
                  "<span class='text-danger price'>" +
                  row.goodsNum * row.goodsPrice +
                  "</span>"
                );
              },
            },
            {
              field: "createDate",
              align: "center",
              title: "创建时间",
            },
            {
              field: "operate",
              align: "center",
              title: "操作",
              formatter: btnGroup,
              events: {
                // 事件
                "click .edit-btn": function (event, value, row, index) {
                  edit(row);
                },
                "click .del-btn": function (event, value, row, index) {
                  remove('order-detail', row.id)
                },
              },
            },
          ],
          onLoadSuccess: function () {
            // 数据加载成功时调用的方法
            // 滚动到最底部
            let h = $(document).height() - $(window).height();
            $("body").animate({ scrollTop: h }, 1000);
          },
          onLoadError: function () {
            // 数据加载失败时调用的方法
            setTimeout(function () {
              notify("mdi mdi-close", "数据加载失败!", "danger");
            }, 300);
          },
          onCheck: function () {
            // 复选框单击事件
            getSelections();
          },
        });
      });

      // 操作按钮 - 新增
      function toAdd() {
        $("#myModal").modal("show");
        $("#myModalLabel").html("新增订单详情");
        $("form")[1].reset();
        $("#btn111").html("保存");
      }

      // 操作按钮 - 编辑
      function edit(r) {
        $("#myModal").modal("show");
        $("#myModalLabel").html("修改订单详情");
        $("[name='goodsName']:eq(1)").val(r.goodsName);
        $("[name='goodsNum']").val(r.goodsNum);
        $("[name='goodsUnit']").val(r.goodsUnit);
        $("[name='goodsPrice']:eq(1)").val(r.goodsPrice);
        $("[name='id']").val(r.id);
        $("#btn111").html("修改");
      }

      // 操作方法 - 修改,保存
      function insert_update() {
        let b = false;

        let $goodsName = $("[name='goodsName']:eq(1)");
        let $goodsNum = $("[name='goodsNum']");
        let $goodsUnit = $("[name='goodsUnit']");
        let $goodsPrice = $("[name='goodsPrice']:eq(1)");

        if ($goodsName.val() === "") {
          notify("mdi mdi-close", "商品名称为必填项！", "danger");
          $goodsName.focus();
        } else if ($goodsNum.val() === "") {
          notify("mdi mdi-close", "商品数量为必填项！", "danger");
          $goodsNum.focus();
        } else if ($goodsUnit.val() === "") {
          notify("mdi mdi-close", "商品单位为必填项！", "danger");
          $goodsUnit.focus();
        } else if ($goodsPrice.val() === "") {
          notify("mdi mdi-close", "商品价格为必填项！", "danger");
          $goodsPrice.focus();
        } else {
          b = true;
        }

        if (b) {
          let url =
            $("#btn111").html() === "保存"
              ? "${ctx}/order-detail/save"
              : "${ctx}/order-detail/update";
          let obj = $("form:eq(1)").serializeArray();
          saveOrUpdate(url, obj);
        }
      }
    </script>
  </body>
</html>
